package com.example.mapp.buildSql;

import com.example.entity.training.TrainingPlan;
import com.example.entity.training.TrainingPlanDetail;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;

public class TrainingPlanDetailMappSql {

    /**
     * 查询培训计划 详情
     * @param trainingPlanDetail
     * @return
     */
    public String queryTrainingPlanDetail(TrainingPlanDetail trainingPlanDetail){
        StringBuffer sb = new StringBuffer();
        sb.append(" SELECT * FROM ");
        sb.append(" training_plan_detail where 1=1 ");
        if(trainingPlanDetail.getPlanId() != null){
            sb.append(" and plan_id = #{planId}");
        }
        if(StringUtils.isNotEmpty(trainingPlanDetail.getPartyName())){
            String partyName = "'%"+trainingPlanDetail.getPartyName()+"%'";
            sb.append(" and party_name like "+partyName);
        }
        if(StringUtils.isNotEmpty(trainingPlanDetail.getPlanStatus())){
            sb.append(" and plan_status = #{planStatus}");
        }
        if(StringUtils.isNotEmpty(trainingPlanDetail.getLeadUnit())){
            sb.append(" and lead_unit = #{leadUnit}");
        }
        if(StringUtils.isNotEmpty(trainingPlanDetail.getPartyId())){ //当机构Id不为空时，是履行方获取培训记录
            sb.append(" and party_id = #{partyId}");
            sb.append(" and plan_status in ('1','2')");
        }
        if(StringUtils.isNotEmpty(trainingPlanDetail.getUnitManageUser())){
            String unitManageUser = "'%"+trainingPlanDetail.getUnitManageUser()+"%'";
            sb.append(" and unit_manage_user like "+ unitManageUser);
        }
        if(StringUtils.isNotEmpty(trainingPlanDetail.getStartDate())){
            sb.append(" and start_date >= #{startDate}");
        }
        if(StringUtils.isNotEmpty(trainingPlanDetail.getEndDate())){
            sb.append(" and end_date <= #{endDate}");
        }
        sb.append(" order by id desc ");
        return sb.toString();
    }
}
